﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Duckbill
{
    public class Sprite
    {
        public Texture2D tex;
        public Vector2 size;
        public Color color = Color.White;
        Vector2 texSize;

        public static Vector2 scale = Vector2.One;
        public static Color drawColor = Color.White;
        public static Vector2 offset = Vector2.Zero;

        public Sprite() { }
        public Sprite(Sprite other)
        {
            this.tex = other.tex;
            this.size = other.size;
            this.color = other.color;
            this.texSize = other.texSize;
        }
        public Sprite(ContentManager cMan, string file)
        {
            tex = cMan.Load<Texture2D>(file);
            this.size = new Vector2(tex.Width, tex.Height);
            this.texSize = new Vector2(tex.Width, tex.Height);
        }

        public void Load(ContentManager cMan, string file, Vector2 size)
        {
            tex = cMan.Load<Texture2D>(file);
        }

        public void Draw(SpriteBatch batch, Vector2 pos, float angle=0f, float depth=0.5f)
        {

            Color C = new Color(color.R*Sprite.drawColor.R/255, color.G*Sprite.drawColor.G/255,
                color.B*Sprite.drawColor.B/255, color.A*Sprite.drawColor.A/255);
            Vector2 P = new Vector2((pos.X + size.X/2 + offset.X)*scale.X,
                (pos.Y + size.Y/2 + offset.Y)*scale.Y);
            batch.Draw(tex, new Rectangle((int)P.X, (int)P.Y,
                            (int)(size.X * scale.X), (int)(size.Y * scale.Y)), null, C,
                            angle, texSize/2, SpriteEffects.None, depth);
        }
    }
}
